/*
 * Copyright: Tianjin Berheley Tech Co,.ltd, China
 * biPlatForm
 * com.berheley.bi.beanProcess -> BeanPropertyOverrider.java
 * Created on 2009-10-21-下午01:26:23
 */
package com.webframe.beanProcess;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.RuntimeBeanReference;

/**
 * 类功能描述：
 *
 * @author      <a href="mailto:tozxwu@hotmail.com">wuzhenxue </a>
 * Create:      2009-10-21 下午01:26:23
 * Description: 
 */
public class BeanPropertyOverrider extends AbstractBeanPropertyProcessor {
	
	private static final Log log = LogFactory.getLog(BeanPropertyOverrider.class);

	private Object override;
	private String overrideReference;

	protected Object getProcessedPropertyValue(Object originalValue) {
		if (log.isInfoEnabled()) {
			log.info("Overriding property " + getBeanName() + "." + getPropertyName() + " with " + getOverride());
		}
		
		return getOverrideValue();
	}

	protected Object getOverrideValue() {
		Object value;
		if (overrideReference == null) {
			value = override;
		} else {
			value = new RuntimeBeanReference(overrideReference);
		}
		return value;
	}

	public Object getOverride() {
		return override;
	}

	public void setOverride(Object override) {
		this.override = override;
	}
	
	public String getOverrideReference() {
		return overrideReference;
	}

	public void setOverrideReference(String overrideReference) {
		this.overrideReference = overrideReference;
	}

}
